package com.aviccxzx.smarthome.UserModule;

import android.app.Dialog;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.aviccxzx.smarthome.R;
import com.aviccxzx.smarthome.base.GosUserModuleBaseActivity;
import com.aviccxzx.smarthome.netutil.app.App;
import com.aviccxzx.smarthome.netutil.msg.MsgCenter;


/**
 * Created by joey on 2016/10/25.
 */
public class InputMacActivity extends GosUserModuleBaseActivity implements View.OnClickListener {

    EditText content;//定义一个文本输入框
    TextView hasnum;// 用来显示剩余字数
    int num = 10;//限制的最大字数
    EditText mac_tv;

    private Dialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setContentView(R.layout.enter_number_lay_v19);
        }else {
        }
        ((TextView) findViewById(R.id.title_tv)).setText("添加设备");
        findViewById(R.id.ll_title_left_view).setOnClickListener(this);
        findViewById(R.id.mac_input).setOnClickListener(this);
        mac_tv = (EditText)findViewById(R.id.mac_tv);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_title_left_view:
                finish();
                break;
            case R.id.mac_input:
                String mactv = mac_tv.getText().toString().trim();
                if (stringIsMac(mactv)) {
                    spf.edit().putString("addMac", mactv).commit();
                    MsgCenter.fireNull("mactv",mactv);
                    finish();
                } else {
                    App.getApp().showToast("请输入正确的设备ID");
                }
                break;
        }
    }

    private boolean stringIsMac(String val) {
        String trueMacAddress = "([A-Fa-f0-9]{2}){8}";
        // 这是真正的MAV地址；正则表达式；
        if (val.matches(trueMacAddress)) {
            return true;
        } else {
            return false;
        }
    }
}
